#pragma once

#include <NCore.h>
#include <NImage.h>
#include <SentiSight.h>
#include <NLicensing.h>

#include <string>

class apSSEngine1
{
public:
	apSSEngine1(void);
	~apSSEngine1(void);
	bool Init();
	void Close();
	void DumpInfo();

	//tuning
	bool SetThreadNum(int num);
	bool GetThreadNum(int *pNum);

	bool SetFeaType(int is_learn, int featype);//1-blob,2-shape,3-combined
	bool GetFeaType(int is_learn, int *pType);
	bool SetLrnMode(int mode);//0-low,1-high,2-high ex
	bool GetLrnMode(int *pMode);
	bool SetLrnShapeScalingLvl(int val);
	bool GetLrnShapeScalingLvl(int *pVal);
	bool SetLrnRescaleFactor(double factor);
	bool GetLrnRescaleFactor(double *pVal);

	bool SetRecSpeed(int speed);//0-256
	bool GetRecSpeed(int *pSpeed);
	bool SetRecThr(double val);
	bool GetRecThr(double *pVal);
	bool SetRecUseTracking(int val);
	bool GetRecUseTracking(int *pVal);
	bool SetRecImgRescaleFac(double val);
	bool GetRecImgRescaleFac(double pVal);
	bool SetRecShapeScalingLvl(int val);
	bool GetRecShapeScalingLvl(int pVal);
	bool SetRecThreads(int val);
	bool GetRecThreads(int *pVal);

	//learn
	bool LearnBackground_pic(const char* bgFilename, bool *bMore);
	bool LearnBackground_img(HNImage hImage, bool *bMore);
	bool LearnHolder_pic(const char *srcFilename, HBITMAP *phBmp);
	bool LearnHolder_img(HNImage hImage, HBITMAP *phBmp);
	bool Learn_pic_mask(const char *srcFilename,
		const char *maskFilename, HBITMAP *phBmp);
	bool Learn_pic_shape(const char *srcFilename,
		HSEShape *hShapes, int shapeCnt, HBITMAP *phBmp);
	bool Learn_img_mask(HNImage hImage, HNImage hMask, HBITMAP *phBmp);
	bool Learn_img_shape(HNImage hImage, HSEShape *hShapes, int shapeCnt,
		HBITMAP *phBmp);
	bool GenShape(HSEShape *phShape, NPointD *points, int pointCnt);
	
	//generate
	bool CreateModel();
	bool GenHolder();
	bool GenModel();
	int GetModelSize();
	bool GetModelData(char *pData);
	
	//reset
	bool ResetBackground();

	//recognize
	bool LoadModel_mem();
	bool LoadModel_file(const char *modelFilename, int modId = 0);
	bool RemoveModel(int modId);
	bool RemoveAllModel();
	bool RecImage_pic(const char *srcFilename, bool *pIsRec);
	bool RecImage_img(HNImage hImage, bool *pIsRec);
	bool GetRecNumber(int *pNum);
	bool GetScore(int index, double *pScore);//index based on 0
	bool GetModelId(int index, void **pModelId);
	bool GetShapePoints(int index, NPointD *points, int *pCount);
	bool GetShapeCenter(int index, NPointD *pCenter);
	bool GetShapeHeading(int index, double *pHeading);
	void ResetRecCount(){m_llHitCnt = 0; m_llRecCnt = 0;}
	LONGLONG GetHitCnt(){return m_llHitCnt;}
	LONGLONG GetRecCnt(){return m_llRecCnt;}

	void GetRecStat();
private:
	bool ReadAllBytes(const NChar * szFileName, NByte ** ppBuffer, NSizeType * pSize);
	bool ReadAllBytesN(const NChar * szFileName, HNBuffer * phBuffer);
private:
	HSEEngine		m_hSE;
	HSEModel		m_hModel;
	HNBuffer		m_hBuffer;
	bool			m_inited;
	bool			m_BGlearned;
	LONGLONG		m_llRecCnt;
	LONGLONG		m_llHitCnt;
	int				m_recNum;
};

